import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBconnection {

	static Connection c;

	public static void setConn() {
		try {
			c = DriverManager.getConnection("jdbc:mysql://data.infeo.at/fhv",
					"fhv", "fhv");

			System.out.println("Datenbank Verbindung hergestellt!");

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws SQLException {
		setConn();
		statement();
	}

	public static void statement() throws SQLException {
		Statement stmt = c.createStatement();
		ResultSet rs = stmt
				.executeQuery("SELECT persno, fname , lname FROM person");

		while (rs.next()) {
			Person p = new Person();

			p.setPersno(rs.getInt("persno"));
			p.setFname(rs.getString("fname"));
			p.setLname(rs.getString("lname"));
			System.out.println(p.toString());
		}

	}
}